<template>
<div>
  <button @click='post'>post</button>
  <button @click='axios'>axios</button>

</div>
</template>

<script>
import qs from 'qs'

export default {
  name: 'haha',
  data() {
    return {}
  },
  methods: {
    post() {
      console.log('sdf');
      const xhr = new XMLHttpRequest();
      const fd = new FormData();
      fd.append('d', 'dd')
      xhr.open('post', 'http://14.215.50.212:8888/cors/posttest');
      // xhr.setRequestHeader('content-type','application/x-www-form-urlencoded;charset=UTF-8');
      // xhr.send(fd);
      xhr.setRequestHeader('content-type','application/json;charset=UTF-8');
      xhr.send({d: 'dd'})
      xhr.onreadystatechange = () => {
        if(xhr.readyState === 4 && xhr.status === 200) {
          console.log(xhr.responseText);
        }
      }
    },
    axios() {
      // 发送一个预检请求     

      console.log('sdf', qs.stringify({d:'dd'}));

      this.$http.post('http://14.215.50.212:8888/cors/posttest',
      qs.stringify({d:'dd'}),
      // {},
      {headers: {
        'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'
      }}
      ).then(res => {
        console.log(res)
      })
    }
  }
}
</script>

<style>

</style>
